package com.homework.mergesort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class ReduceMS extends Reducer<MSBean, NullWritable, IntWritable, MSBean> {
    private int sum = 0;
    IntWritable k = new IntWritable();

    @Override
    protected void reduce(MSBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        //每个key的数据进行写入
        for (NullWritable text : values) {
            //每次执行reduce进行加一作为排名字段
            sum += 1;
            k.set(sum);
            context.write(k, key);
        }
    }
}
